home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-05-12 | 4.4 KB | 134 lines | [TEXT/ttxt] |
- \ serial - async serial driver support
- \ 2/04/85 cbd Version 1
- \ 9/04/86 cdn Eliminated redundant readnw: & writenw
- \ 9/06/86 cdn Added bi-directional port usage
- \ Automatically send reset: in open:
- \ 4/19/89 rfl added break:
- \ 6/13/89 rfl requires interval for pause
- \ 3/14/90 rfl added buffer:
- \ 8/16/90 rfl added baudrate: and XON:
- \ 10/09/90 rfl added status: and bytesIn:
- \ 10/19/90 rfl added flags and Device Control Record ptr
- \ 10/30/90 rfl added DTR handshake (pin 6)
- \ 5/12/93 rfl set DTR false during Open: to take care of problem with powerbooks
-
- Decimal
-
- \ define serial i/o port object
- :CLASS Port <Super PBDrvr
-
- Int thePort \ 0=modem, 1=printer
- Int Direction \ 0=input, 1=output, 2=both
- Int Config \ bits, parity, speed
- Int inRef \ input IORefNum
- Int outRef \ output IORefNum
-
- \ ( port# direction -- )
- :M INIT: put: direction put: thePort ;M
-
- \ ( config -- ) set the config word directly
- :M SETCONFIG: put: config ;M
-
- \ ( stop data parity -- ) set stop, data bits in the config word
- \ stop can be 1 or 2
- \ data can be 7 or 8
- \ parity: 0=none 1=odd 2=even
- :M CONFIG: { stop data parity -- } data 7 =
- IF $ 400 ELSE $ C00 THEN -> data stop 1 =
- IF $ 4000 ELSE $ C000 THEN -> stop parity 0=
- IF $ 2000
- ELSE parity 1 =
- IF $ 1000
- ELSE $ 3000
- THEN
- THEN -> parity
- get: config $ 01FF and data stop parity + + or
- put: config ;M
-
- \ set the baud rate for the port - 300,600,1200,2400, etc.
- :M BAUD: dup 300 =
- IF 80 +
- ELSE 300 / 380 swap / 1-
- THEN get: config $ FE00 and or put: config
- ;M
-
- \ do PBControl call
- :M CONTROL:
- get: direction dup 0= swap 2 = or
- IF get: inRef put: IORefNum addr: header fcall PBControl drop THEN
- get: direction
- IF get: outRef put: IORefNum addr: header fcall PBControl drop THEN
- ;M
-
- :M STATUS: addr: header fcall PbStatus abort" status error" ;M
-
- :M DTR: ( b -- fcode) get: direction dup 0= swap 2 = or classerr" 158
- addr: csp1 10 erase addr: csP1 7 + c! 14 put: csCode
- clear: IOComp control: self get: IOResult ;M
-
- \ set the communication parms from the configuration word
- :M RESET: 8 put: csCode get: config put: csp1 0 put: IOComp
- control: self ;M
-
- \ ( addr len -- RefNum )
- :M OPN: name: super open: super drop get: IORefNum ;M
-
- \ ( -- ) open the read and write drivers for a port
- :M OPEN: get: thePort 0=
- IF get: direction dup 0= swap 2 = or
- IF " .AIn" opn: self put: inRef THEN
- get: direction
- IF " .AOut" opn: self put: outRef THEN
- ELSE get: direction dup 0= swap 2 = or
- IF " .BIn" opn: self put: inRef THEN
- get: direction
- IF " .BOut" opn: self put: outRef THEN
- THEN get: IOResult
- reset: self
- get: direction IF 0 dtr: self drop THEN \ take care dtr problem with pbooks
- ;M
-
- \ ( addr len -- fcode ) receive LEN bytes on the serial port
- :M READ: 0 put: IOComp get: inRef put: IORefNum read: super ;M
-
- \ ( addr len -- fcode ) send LEN bytes on the serial port
- :M WRITE: 0 put: IOComp get: outRef put: IORefNum write: super ;M
-
- \ ( cfa:proc addr len ) receive LEN bytes asynchronously on the port
- :M READNW: get: inRef put: IORefNum readnw: super ;M
-
- \ ( cfa:proc addr len ) send LEN bytes asynchronously on the port
- :M WRITENW: get: outRef put: IORefNum writenw: super ;M
-
- \ ( -- char ) get a single character from port
- :M GET: pad 1 read: self drop pad c@ ;M
-
- \ ( char -- ) send a single char to port
- :M PUT: pad c! pad 1 write: self drop ;M
-
- \ ( bool -- fcode ) turn CTS handshaking on or off via CONTROL call
- :M CTS: addr: csp1 10 erase put: csp1 10 put: csCode 0 put: IOComp
- control: self get: IOResult ;M
-
- :M XON: ( b -- fcode) addr: csP1 c! $ 1113 put: csP2 10 put: cscode control: self
- get: IOResult ;M
-
- \ sends out a 100 msec break
- :M BREAK: 12 put: csCode control: self 6 pause 11 put: csCode control: self ;M
-
- \ ( addr len -- ) increase internal buffer size from default of 64 bytes
- :M BUFFER: addr: IOBuffer w! +base addr: csP1 ! 9 put: cscode control: self ;M
-
- :M BAUDRATE: ( n --) dup baud: self 13 put: cscode put: csP1 control: self ;M
-
- \ # of bytes in port, before reading
- :M BYTESIN: ( -- n) 2 put: cscode status: self addr: csp1 @ ;M
-
- :M RECORD: ( -- ptr) global uTableBase @ -base get: ioRefNum 1+ negate 4* + @ >ptr ;M
-
- :M FLAGS: ( -- n) record: self 4+ w@ ;M
-
- :M ISOPEN: ( -- b) flags: self $ 20 and IF true ELSE false THEN ;M
-
- ;CLASS
-